package main

import (
	"fmt"
	"time"
)

func main() {
	// select 功能：解决多个管道的选择问题，也可以叫做多路复用，可以从多个管道中随机公平的选择一个管道来执行

	var intChan chan int = make(chan int, 1)
	var stringChan chan string = make(chan string, 1)

	//go func() {
	//	time.Sleep(time.Second * 2)
	//	intChan <- 1
	//}()
	//go func() {
	//	time.Sleep(time.Second * 10)
	//	stringChan <- "哈哈哈哈啊哈"
	//}()

	go func() {
		intChan <- 1
		time.Sleep(time.Second * 2)
	}()
	go func() {
		stringChan <- "哈哈哈哈啊哈"
		time.Sleep(time.Second * 10)
	}()

	select {
	case v := <-intChan:
		fmt.Println("intChan:", v)
	case s := <-stringChan:
		fmt.Println("stringChan:", s)
		//default:
		//	fmt.Println("防止select被阻塞，执行非阻塞")
	}
}
